package com.zys.sac.core.provider;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.authentication.CredentialsExpiredException;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * Created by zhongjunkai on 2022/10/19.
 */
@Slf4j
public class PlainModeUserAuthenticationProvider extends AbstractSacUserAuthenticationProvider {

    private PasswordEncoder bCryptPasswordEncoder;

    public PlainModeUserAuthenticationProvider(PasswordEncoder bCryptPasswordEncoder) {
        this.bCryptPasswordEncoder = bCryptPasswordEncoder;
    }

    @Override
    protected void doMatchPassword(String password, String dbPassword) {
        if(!bCryptPasswordEncoder.matches(password, dbPassword)) {
            throw new CredentialsExpiredException("用户名或密码错误");
        }
    }
}
